package com.c201801020208.ybl.Company;

import android.content.Intent;
import android.os.Bundle;

import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.c201801020208.ybl.Adapters.HomePageAdapter;
import com.c201801020208.ybl.R;
import com.c201801020208.ybl.User.Activity.SearchActivity;

public class MyCompanyFirstFragment extends Fragment {
    private RecyclerView recyclerView;
    private View view;
    private boolean IS_LOADED = false;
    private static int mSerial = 0;
    private int mTabPos = 0;
    private boolean isFirst = true;
    private String type;
    private View Search;

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }


    private Handler handler = new Handler() {
        public void handleMessage(Message msg) {
            Log.e("tag", "IS_LOADED=" + IS_LOADED);

            IS_LOADED = true;
            //这里执行加载数据的操作
            recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
            HomePageAdapter adapter = new HomePageAdapter(getActivity(), type);
            recyclerView.setAdapter(adapter);
            adapter.notifyDataSetChanged();
            Log.e("tag", "我是page" + (type));

            return;
        }

        ;
    };

    public MyCompanyFirstFragment(int serial, String type) {
        mSerial = serial;
        this.type = type;
    }

    public void sendMessage() {
        Message message = handler.obtainMessage();
        message.sendToTarget();
    }

    public void setTabPos(int mTabPos) {
        this.mTabPos = mTabPos;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.fragment_my_company_first, container, false);
        recyclerView = rootView.findViewById(R.id.recyclerview);
        Search = rootView.findViewById(R.id.search);
        if (isFirst && mTabPos == mSerial) {
            isFirst = false;
            sendMessage();
        }
        Search.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(getActivity(), SearchActivity.class);
                startActivity(intent);
            }
        });
        return rootView;
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
    }
}